/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * guiPlaylistView.java
 *
 * Created on 11/06/2011, 14:20:46
 */

package guiPlaylisted.view;


import dataPlaylisted.Playlist;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;

/**
 *
 * @author Administrador
 */
public class guiPlaylistCreateView extends javax.swing.JDialog {

    private static Playlist m_playlist;

    private PlaylistView m_playlistView;


    /** Creates new form guiPlaylistView */
    public guiPlaylistCreateView(java.awt.Frame parent, boolean modal, Playlist _playlist) throws FileNotFoundException, IOException, ClassNotFoundException {
        super(parent, modal);
        initComponents();

        m_playlist = _playlist;
        m_playlistView = PlaylistView.getInstance();

        this.showPlaylist(m_playlist);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPlaylist = new javax.swing.JTextPane();
        jLabel5 = new javax.swing.JLabel();
        jBtSalvar = new javax.swing.JButton();
        jBtCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextPlaylist.setName("jTextPlaylist"); // NOI18N
        jScrollPane1.setViewportView(jTextPlaylist);

        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getActionMap(guiPlaylistCreateView.class, this);
        jBtSalvar.setAction(actionMap.get("onSave")); // NOI18N
        jBtSalvar.setName("jBtSalvar"); // NOI18N

        jBtCancel.setName("jBtCancel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(120, 120, 120)
                .addComponent(jLabel5)
                .addContainerGap(282, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(247, Short.MAX_VALUE)
                        .addComponent(jBtSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBtCancel)))
                .addGap(29, 29, 29))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtSalvar)
                    .addComponent(jBtCancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    guiPlaylistCreateView dialog = new guiPlaylistCreateView(new javax.swing.JFrame(), true, m_playlist);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(guiPlaylistCreateView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(guiPlaylistCreateView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(guiPlaylistCreateView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    private void showPlaylist(Playlist _playlist){
        Playlist _musicList;
        _musicList = _playlist;

        String _strList;
        _strList = new String();
        for (int i=0; i < _musicList.getPlaylist().size(); i++){
            _strList = _strList.concat(_musicList.getPlaylist().get(i).getArtistName() + " " + _musicList.getPlaylist().get(i).getTrackName() + " " +
                    _musicList.getPlaylist().get(i).getSyle() + " " + _musicList.getPlaylist().get(i).getCammelot()+ " \n");
        }
        jTextPlaylist.setText(_strList);
    }

    @Action
    public void onSave() throws ClassNotFoundException {

        m_playlistView.savePlaylist();

        this.dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtCancel;
    private javax.swing.JButton jBtSalvar;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPlaylist;
    // End of variables declaration//GEN-END:variables

}
